﻿using Microsoft.AspNetCore.Mvc;
using RSFrame.Services;
using RSModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RSWebAPIs.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AppointmentsController : ControllerBase
    {
        public AppointmentsController(IAppointmentService appointmentService)
        {
            AppointmentService = appointmentService;
        }

        public IAppointmentService AppointmentService { get; set; }

        [HttpGet("{appointmentID}")]
        public Appointment GetAppointment(int appointmentID)
        {
            return AppointmentService.GetAppointment(appointmentID);
        }

        [HttpGet("{userID}")]
        public List<Appointment> GetAppointmentsByUserID(int userID)
        {
            return AppointmentService.GetAppointmentsByUserID(userID);
        }

        [HttpGet("{appointmentID}")]
        public ActionResult GetAppointmentStatus(int appointmentID)
        {
            ActionResult actionResult = new() { Status = "succeed" };
            try
            {
                actionResult.Details = AppointmentService.GetAppointment(appointmentID).Processed;
            }
            catch
            {
                actionResult.Status = "failed";
            }
            return actionResult;
        }

        [HttpPost]
        public ActionResult AddAppointment([FromForm] Appointment value)
        {
            ActionResult actionResult = new() { Status = "succeed" };
            try
            {
                actionResult.Details = AppointmentService.AddAppointmnet(value).ToString();
            }
            catch
            {
                actionResult.Status = "failed";
            }
            return actionResult;
        }

        //[HttpPut("{id}")]
        //public void Put(int id, [FromBody] string value)
        //{
        //}

        //[HttpDelete("{id}")]
        //public void Delete(int id)
        //{
        //}
    }
}
